package com.seventh.parkingrent.service.impl;

import com.seventh.parkingrent.controller.form.UserAuditForm;
import com.seventh.parkingrent.controller.form.UserAuditFormForFront;
import com.seventh.parkingrent.domain.UserAudit;
import com.seventh.parkingrent.dao.UserAuditMapper;
import com.seventh.parkingrent.service.IUserAuditService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 用户审核记录表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
@Service
public class UserAuditServiceImpl extends ServiceImpl<UserAuditMapper, UserAudit> implements IUserAuditService {
    @Resource
    private UserAuditMapper userAuditMapper;

    @Override
    public Integer addUserAuditResult(UserAuditForm userAuditForm) {
        UserAudit userAudit = new UserAudit();
        BeanUtils.copyProperties(userAuditForm,userAudit);
        int insert = userAuditMapper.insert(userAudit);
        return insert;
    }

    @Override
    public List<UserAuditFormForFront> getUserAuditByCondition(String managerName, String username, String beginTime, String endTime) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date beginDate=null;
        Date endDate=null;
        if(null!=beginTime){
            String beginDay = beginTime.substring(0,beginTime.indexOf("T"));
            beginDate = format.parse(beginDay);
        }else{
            beginDate=format.parse("2021-08-01");
        }
        if(null!=endTime){
            String endDay = endTime.substring(0,endTime.indexOf("T"));
            endDate = format.parse(endDay);
        }else{
            Date newDate = new Date();
            String s = format.format(newDate);
            String substring = s.substring(0, 10);
            endDate=format.parse(substring);
        }

        List<UserAuditFormForFront> form = userAuditMapper.selectUserAuditByCondition(managerName,username,beginDate,endDate);

        return form;
    }
}
